var copyOpt = {
	currRightDom:null,
	setRightClickListener:function(){
		$(document).on("mousedown",function(e){
			if(e.which == 3){
				copyOpt.currRightDom = e.target;
			}
		});
	},
	copyTextToClipboard:function(text) {
	  var copyFrom = document.createElement("textarea");
	  copyFrom.textContent = text;
	  document.body.appendChild(copyFrom);
	  copyFrom.select();
	  document.execCommand('copy');
	  copyFrom.blur();
	  document.body.removeChild(copyFrom);
	},
	getFromClipboard:function(){
		var t = document.createElement("input");
		document.body.appendChild(t);
		t.focus();
		document.execCommand("paste");
		var clipboardText = t.value; //this is your clipboard data
		document.body.removeChild(t);
		return clipboardText;
	},
	copy:function(){
		if(copyOpt.currRightDom){
			var curr = $(copyOpt.currRightDom);
			if(curr && curr.length > 0){
				var tagName = copyOpt.currRightDom.tagName;
				var val = "";
				if(tagName == "CODE" || tagName == "code"){
					val = curr.text();
				}else{
					var p = curr.parents("code");
					if(p && p.length > 0){
						val = p.text();
					}else{
						alert("没有code元素");
					}
				}
				console.info(val)
				copyOpt.copyTextToClipboard(val);
			}else{
				return;
			}
			
		}
	}
}
copyOpt.setRightClickListener();
